package guda.shop.cms.manager.impl;

import guda.shop.cms.dao.BrandDao;
import guda.shop.cms.entity.Brand;
import guda.shop.cms.manager.BrandMng;
import guda.shop.cms.manager.BrandTextMng;
import guda.shop.cms.manager.ProductTypeMng;
import guda.shop.common.hibernate3.Updater;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class BrandMngImpl
        implements BrandMng {
    private ProductTypeMng productTypeMng;
    private BrandTextMng brandTextMng;
    private BrandDao brandDao;

    @Transactional(readOnly = true)
    public List<Brand> getAllList() {
        List localList = this.brandDao.getAllList();
        return localList;
    }

    public List<Brand> getList() {
        return this.brandDao.getList();
    }

    public List<Brand> getListForTag(Long paramLong, int paramInt1, int paramInt2) {
        return this.brandDao.getList(paramLong, paramInt1, paramInt2, true);
    }

    public Brand getsiftBrand() {
        return this.brandDao.getsiftBrand();
    }

    @Transactional(readOnly = true)
    public Brand findById(Long paramLong) {
        Brand localBrand = this.brandDao.findById(paramLong);
        return localBrand;
    }

    public Brand save(Brand paramBrand, String paramString) {
        Brand localBrand = this.brandDao.save(paramBrand);
        this.brandTextMng.save(localBrand, paramString);
        return localBrand;
    }

    public Brand update(Brand paramBrand, String paramString) {
        Updater localUpdater = new Updater(paramBrand);
        Brand localBrand = this.brandDao.updateByUpdater(localUpdater);
        localBrand.getBrandText().setText(paramString);
        return localBrand;
    }

    public Brand deleteById(Long paramLong) {
        Brand localBrand = findById(paramLong);
        localBrand = this.brandDao.deleteById(paramLong);
        return localBrand;
    }

    public Brand[] deleteByIds(Long[] paramArrayOfLong) {
        Brand[] arrayOfBrand = new Brand[paramArrayOfLong.length];
        int i = 0;
        int j = paramArrayOfLong.length;
        while (i < j) {
            arrayOfBrand[i] = deleteById(paramArrayOfLong[i]);
            i++;
        }
        return arrayOfBrand;
    }

    public Brand[] updatePriority(Long[] paramArrayOfLong, Integer[] paramArrayOfInteger) {
        Brand[] arrayOfBrand = new Brand[paramArrayOfLong.length];
        int i = 0;
        int j = paramArrayOfLong.length;
        while (i < j) {
            arrayOfBrand[i] = findById(paramArrayOfLong[i]);
            arrayOfBrand[i].setPriority(paramArrayOfInteger[i]);
            i++;
        }
        return arrayOfBrand;
    }

    public boolean brandNameNotExist(String paramString) {
        return this.brandDao.countByBrandName(paramString) <= 0;
    }

    @Autowired
    public void setProductTypeMng(ProductTypeMng paramProductTypeMng) {
        this.productTypeMng = paramProductTypeMng;
    }

    @Autowired
    public void setBrandTextMng(BrandTextMng paramBrandTextMng) {
        this.brandTextMng = paramBrandTextMng;
    }

    @Autowired
    public void setDao(BrandDao paramBrandDao) {
        this.brandDao = paramBrandDao;
    }
}

